home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / em7sui_1 / DAOCON.CL_ / DAOCON.CL
Text File  |  1998-12-15  |  2KB  |  77 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "DAOCon"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. 'connection to the database
  13. Private m_objConnect As Database
  14.  
  15. 'the status of the connection
  16. Private m_bIsConnected As Boolean
  17.  
  18. Public Function ConnectToDB() As Boolean
  19. 'returns true if connected to database, false if not
  20.  
  21. On Error GoTo trap_err
  22.  
  23. ' open the connection to data source
  24. Set m_objConnect = Workspaces(0).OpenDatabase(App.Path & "\DB401k.mdb", False, True)
  25. m_bIsConnected = True
  26. ConnectToDB = True
  27. Exit Function
  28.  
  29. trap_err:
  30.     Call MsgBox("Could not connect to DB401k.mdb.  Make sure that this database is in the application's directory.", vbExclamation, "401k Report")
  31.     m_bIsConnected = False
  32.     ConnectToDB = False
  33.  
  34. End Function
  35.  
  36. Private Sub Class_Initialize()
  37.  
  38. Set m_objConnect = Nothing
  39. m_bIsConnected = False
  40.  
  41. End Sub
  42.  
  43. Private Sub Class_Terminate()
  44.  
  45. If Not (m_objConnect Is Nothing) Then
  46.     'close the connection
  47.     m_objConnect.Close
  48. End If
  49.  
  50. End Sub
  51.  
  52. Public Property Get IsConnected() As Boolean
  53.  
  54. IsConnected = m_bIsConnected
  55.  
  56. End Property
  57.  
  58. Public Property Get DBConnection() As Database
  59.  
  60. Set DBConnection = m_objConnect
  61.  
  62. End Property
  63.  
  64. Public Function RunRetrieveQuery(sqlString As String) As Recordset
  65.  
  66. On Error GoTo bad_sql
  67.  
  68. Set RunRetrieveQuery = m_objConnect.OpenRecordset(sqlString, dbOpenSnapshot, dbReadOnly)
  69. Exit Function
  70.  
  71. bad_sql:
  72.     Set RunRetrieveQuery = Nothing
  73.     m_bIsConnected = False
  74.  
  75. End Function
  76.  
  77.